package service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import entity.LayRequest;
import entity.Users;
import mapper.UsersMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UsersServiceImpl implements UsersService {
    @Autowired
    private UsersMapper usersMapper;
    @Override
    public Users selectByAccount(String account) {
        Users users=usersMapper.selectByAccount(account);
        return users;
    }

    @Override
    public boolean update(Users users) {
        return usersMapper.update(users)>0?true:false;
    }

    @Override
    public boolean insert(Users users) {
        return usersMapper.insert(users)>0?true:false;
    }

    @Override
    public boolean delete(Integer id) {
        return usersMapper.delete(id)>0?true:false;
    }

    @Override
    public Users selectById(Integer id) {
        Users users = usersMapper.selectById(id);
        return users;
    }

    @Override
    public PageInfo<Users> selectByPage(LayRequest layRequest) {
        //1.设置当前页和每页记录数
        PageHelper.startPage(layRequest.getPage(),layRequest.getLimit());
        //2. 执行查询
        List<Users> adminList= usersMapper.selectByMap(layRequest.getParams());
        //3.创建PageInfo对象
        return new PageInfo<>(adminList);
    }
}
